package app.action;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.JFileChooser;

import app.ui.AbsCommonPanel;
import app.ui.MainFrame;
import app.ui.MakeDataFileUi;

public class SelectMP3FileAction extends AbsCommonPanelAction {
	protected JFileChooser jFileChooser;
	protected FileUtilities filter;
	protected File file;
	public static final String[] extension = { "mp3", "dat" };

	public SelectMP3FileAction(AbsCommonPanel mPanel) {
		super(mPanel);
		jFileChooser = new JFileChooser();
		filter = new FileUtilities(extension);
		jFileChooser.setFileFilter(filter);
	}

	public void actionPerformed(ActionEvent e) {
		String lastDir = mPanel.getmFrame().getAppProp().getProperty(MainFrame.LASTDIR);
		jFileChooser.setCurrentDirectory(new File(lastDir));
		int num = jFileChooser.showDialog(mPanel, "Select");
		if (num == JFileChooser.APPROVE_OPTION) {
			this.file = jFileChooser.getSelectedFile();
			if (filter.getExtension(file).equals(extension[0])
					|| filter.getExtension(file).equals(extension[1])) {
				mPanel.getmFrame().setCurrentDirectory(file);
				doSpecificPanelAction();
			}
		}
	}

	@Override
	protected void doSpecificPanelAction() {
		((MakeDataFileUi) mPanel).getjTextFields()[0].setText(file.getPath());
	}

}
